<template>
  <div>
    <h1>登陆</h1> <br>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="账号">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" show-password></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="toLogin">登陆</el-button>
        <el-button  @click="toRegister()">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data(){
    return{
      form:{
        username:"",
        password:""
      }
    }
  },
  methods:{
    toLogin(){
      this.axios.post("/user/login",this.form).then(res=>{
        if(res.data){
          // 存在哪？
          localStorage.setItem("user",JSON.stringify(res.data));
          this.$message.success("登陆成功！");
          this.$router.push("/index");
        }else{
          this.$message.error("登陆失败！");
        }
      })
    },
    toRegister(){
      this.$router.push('/register');
    }
  }
}

</script>


<style>

</style>